package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// Item represents a simple data structure
type Item struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

func main() {
	// Create a new Gin router with default middleware
	router := gin.Default()

	// Define routes
	router.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})

	// GET /items - Get all items
	router.GET("/items123", func(c *gin.Context) {
		items := []Item{
			{ID: "1", Name: "Item 1"},
			{ID: "2", Name: "Item 2"},
		}
		c.JSON(http.StatusOK, items)
	})

	// GET /items/:id - Get item by ID
	router.GET("/items/:id", func(c *gin.Context) {
		id := c.Param("id")
		item := Item{ID: id, Name: "Item " + id}
		c.JSON(http.StatusOK, item)
	})

	// POST /items - Create new item
	router.POST("/items", func(c *gin.Context) {
		var newItem Item
		if err := c.ShouldBindJSON(&newItem); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}
		c.JSON(http.StatusCreated, newItem)
	})

	// Run the server on port 8080
	router.Run(":8089")
}
